$(function(){	
		
	var BASE_URL='<?php echo base_url();?>';
	var menu_id ='<?php echo $this->session->userdata("menu");?>';	
	
	var btn=['Insert','Delete'];
	var btn_title='';
	
	
	
	//set the button
	for(var i=0;i<btn.length;i++){
		$('.headerForm').append('<a href=# class="btn-small" id="'+btn[i]+'">'+btn[i]+'</a>');		
	}			
	
	function showAlert(type,str){
		var el=$('#myMsg');
		var w=str.length +20;
		var t=el.height+20;
		
		el.hide();
		switch(type){
			case 0://info
				el.empty().addClass('msgInfo');
			break;
			case 1://notification
				el.empty().addClass('msgNotif');
			break;
			case 2://error
				el.empty().addClass('msgError');
			break;
		}
		el.append(str).css({'width':'w','height':'t'}).show().animate({'left':1000,'top':15},'fast');
	}
	
	// update absen per 3 detik
	var BASE_URL='<?php echo base_url();?>';
	var menu_id ='<?php echo $this->session->userdata("menu");?>';	
	
	function cekAbsen(){		
		$.ajax({
			type		:'GET',
			url			: BASE_URL+'ajax/updateAbsenToday',
			beforeSend	: function(){
				$('#loader-content').empty().append('<img src="<?php echo base_url();?>assets/img/loader.gif"> Sedang meng-update absen ....');
				$('#loader-content').show();	
			},
			success:function(data){
				$('#loader-content').hide();
				$('#absen-content').empty().html(data);
			}
		});		
		//var waktu = setTimeout('cekAbsen()',3000);
	}
	if(menu_id=='absensi'){
		cekAbsen();
	}	
	
	function showClock(){			
		var clock=new Date();
		var hours=clock.getHours();
		var minutes=clock.getMinutes();
		var seconds=clock.getSeconds();		
		if (hours<10){
			hours="0" + hours;
		}
		if (minutes<10){
			minutes="0" + minutes;
		}
		if (seconds<10){
			seconds="0" + seconds;
		}
		document.getElementById('jam').innerHTML=hours+":"+minutes+":"+seconds;
		t=setTimeout('showClock()',500);
	}
	//showClock();
	
	$('#btnRefresh').click(function(){
		cekAbsen();
	});
		
});
